<?php Schema::init(); ?>
<script type="text/javascript">
var cat_types = [];
<?php foreach (Config::get('category_types') as $cat_type_id) { ?>
	cat_types.push(<?php echo $cat_type_id;?>);
<?php } ?>
function switch_category_tipe(type_id) {
	for (var ct in cat_types) {
		var cat_type =  $('#cats_type_' + cat_types[ct]);
		if (cat_type) {
			if (parseInt(cat_types[ct]) == parseInt(type_id)) {
				cat_type.show();
			} else {
				cat_type.hide();
			}
		}
		$('#cat_parent_id_' + cat_types[ct]).val(0);
	}
}

$(function () {
	$('#cats_type_' + $('#cat_type_id').val()).show();
});
</script>
<div class="schema_wrapper">
	<?php if ($error > -1) { ?>
		<div class="schema_message">
		<?php if (!$error) {
			Backend::infoMessage(__('Category inserted sucsesfuly'));
		} else {
			Backend::errorMessage(__('Error inserting category'));
		} ?>
		</div>
	<?php } ?>
	<div class="schema_header">
		<?php echo __('Inserting category'); ?>
	</div>
	<form action="<?php echo CURRENT_URL; ?>" method="post">
		<div class="schema_tabs">
			<ul class="nav nav-pills">
				<li id="schema_tab_0" class="active">
					<a href="#0" onclick="Core.Schema.openTab(0)"><?php echo __('General'); ?></a>
				</li>
			<?php Schema::drawTabs('category.xml'); ?>
			</ul>
		</div>
		<div class="schema_blocks">
			<div class="schema_block" id="schema_block_0">
				<table class="table">
					<colgroup>
						<col class="schema_column_headers" />
						<col class="schema_column_fields" />
					</colgroup>
					<tbody>
						<tr>
							<td class="schema_cell_header"><?php echo __('Category name'); ?></td>
							<td class="schema_cell_field"><input type="text" name="cat_name" class="schema_textfield" /></td>
						</tr>
						<tr>
							<td class="schema_cell_header"><?php echo __('Alias'); ?></td>
							<td class="schema_cell_field"><input type="text" name="cat_alias" class="schema_textfield" /></td>
						</tr>
						<tr>
							<td class="schema_cell_header"><?php echo __('Status'); ?></td>
							<td class="schema_cell_field">
								<select name="cat_status_id" class="schema_select">
									<option value="1"><?php echo __('Opened'); ?></option>
									<option value="2"><?php echo __('Closed'); ?></option>
								</select>
							</td>
						</tr>
						<tr>
							<td class="schema_cell_header"><?php echo __('Category type'); ?></td>
							<td class="schema_cell_field">
								<select id="cat_type_id" name="cat_type_id" class="schema_select" onchange="switch_category_tipe(this.value)">
								<?php foreach (Config::get('category_types') as $cat_type) { ?>
									<option value="<?php echo $cat_type; ?>"><?php echo __('category_type_single_' . $cat_type); ?></option>
								<?php } ?>
								</select>
							</td>
						</tr>
					<?php foreach (Config::get('category_types') as $cat_type_id) { ?>
						<tr id="cats_type_<?php echo $cat_type_id;?>" style="display:none;">
							<td class="schema_cell_header"><?php echo __('Parent category'); ?></td>
							<td class="schema_cell_field">
								<select id="cat_parent_id_<?php echo $cat_type_id;?>" name="cat_parent_id_<?php echo $cat_type_id;?>" class="schema_select">
									<?php Category::drawTreeSelect($cat_type_id); ?>
								</select>
							</td>
						</tr>
					<?php } ?>
					</tbody>
				</table>
			</div>
			<?php Schema::drawBlocks('category.xml'); ?>
		</div>
		<div class="schema_buttons"><input type="submit" value="<?php echo __('Insert'); ?>" class="btn btn-primary" /></div>
	</form>
</div>